package com.googlecode.articulando.framework.util;

import java.io.*;
import java.util.Properties;

import com.googlecode.articulando.framework.exception.ArticulandoException;

public class Articulando {

	private static final String ARQUIVO_PROPERTIES = "articulando.properties";

	private static Articulando instance;
	private Properties properties;

	public static Articulando getInstance() {
		if (instance == null) {
			instance = new Articulando();
		}
		return instance;
	}

	private Articulando() {
		// singleton
	}

	private Properties getArquivoProperties() throws ArticulandoException {
		if (this.properties == null) {
			try {
				FileInputStream f = new FileInputStream(new File(
						ARQUIVO_PROPERTIES));
				this.properties = new Properties();
				this.properties.load(f);
			} catch (FileNotFoundException e) {
				this.properties = null;
				e.printStackTrace();
				throw new ArticulandoException(e);
			} catch (IOException e) {
				this.properties = null;
				e.printStackTrace();
				throw new ArticulandoException(e);
			}
		}
		return this.properties;
	}

	public String getPropriedade(String prop) throws ArticulandoException {
		return getArquivoProperties().getProperty(prop);
	}

}
